package com.baturu.vin.hyundai.dal.dao;

import com.baturu.vin.hyundai.dal.entity.SEPCHyundaiSubGroupEntity;
import com.baturu.vin.hyundai.dto.HyundaiKiaPartsMappingDTO;
import com.baturu.vin.hyundai.dto.HyundaiKiaVehicleDTO;
import com.baturu.vin.hyundai.dto.KiaPartsDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

/**
 * 东风起亚编码表
 *
 * @Author: chenjiahao
 * @Time: 2018/12/5
 */
public interface HyundaiKiaLJDDAO {

    @Select({"<script>SELECT parts_id,groupName,finalPartName,classify,crnm,bpno,startDate startTime,endDate endTime,finalPartCode finalPartsCode,finalGroupCode groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,count,imgX,imgY",
            " FROM hyundai_parts_LJD",
            "WHERE year= #{year}",
            "AND naif = #{naif}",
            "AND micd = #{micd}",
            "AND ocn = #{ocn}",
            "AND ver = #{ver}",
            "AND finalPartCode in ",
            "<foreach item ='item' collection = 'partsCodes' open ='(' separator= ',' close = ')'>",
            "#{item}",
            "</foreach>",
            "AND startdate &lt; #{date}",
            "AND enddate &gt; #{date}",
            "</script>"})
    List<KiaPartsDTO> queryLJDPartsByMapping(@Param("year") String year, @Param("naif") String naif, @Param("micd") String micd, @Param("ocn") String ocn, @Param("ver") String ver, @Param("date") String date, @Param("partsCodes") Collection<String> partsCodes);

    @Select({"<script>SELECT distinct parts_id,epcRemark, finalPartName,crnm,bpno,startDate startTime,endDate endTime,finalPartCode finalPartsCode,finalGroupCode groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,count,imgX,imgY",
            " FROM hyundai_parts_LJD",
            "WHERE year= #{dto.carTypeYear}",
            "AND naif = #{dto.areaNum}",
            "AND micd = #{dto.micd}",
            "AND ocn = #{dto.ocn}",
            "AND ver = #{dto.ver}",
            "AND startdate &lt; #{dto.makeDate}",
            "AND enddate &gt; #{dto.makeDate}",
            "AND groupcode = #{groupDTO.groupCode}",
            "AND imgX = #{groupDTO.imageX}",
            "AND imgY = #{groupDTO.imageY}",
            "</script>"})
    List<KiaPartsDTO> queryLJDPartsByGroup(@Param("groupDTO") SEPCHyundaiSubGroupEntity sepcHyundaiSubGroupEntity, @Param("dto") HyundaiKiaVehicleDTO analyseResult);

    @Select({"<script>SELECT distinct parts_id,epcRemark, finalPartName,crnm,bpno,startDate startTime,endDate endTime,finalPartCode finalPartsCode,finalGroupCode groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,count,imgX,imgY",
            " FROM hyundai_parts_LJD_en",
            "WHERE year= #{dto.carTypeYear}",
            "AND naif = #{dto.areaNum}",
            "AND micd = #{dto.micd}",
            "AND ocn = #{dto.ocn}",
            "AND ver = #{dto.ver}",
            "AND startdate &lt; #{dto.makeDate}",
            "AND enddate &gt; #{dto.makeDate}",
            "AND groupcode = #{groupDTO.groupCode}",
            "AND imgX = #{groupDTO.imageX}",
            "AND imgY = #{groupDTO.imageY}",
            "</script>"})
    List<KiaPartsDTO> queryLJDPartsByGroupEn(@Param("groupDTO") SEPCHyundaiSubGroupEntity sepcHyundaiSubGroupEntity, @Param("dto") HyundaiKiaVehicleDTO analyseResult);


    @Select({"<script>SELECT parts_id,epcRemark,groupName,finalPartName,classify,crnm,bpno,startDate startTime,endDate endTime,finalPartCode finalPartsCode,finalGroupCode groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,count,imgX,imgY",
            " FROM hyundai_parts_LJD",
            "WHERE year= #{year}",
            "AND naif = #{naif}",
            "AND micd = #{micd}",
            "AND ocn = #{ocn}",
            "AND ver = #{ver}",
            "AND finalPartCode like '${partsCode}%' ",
            "AND startdate &lt; #{date}",
            "AND enddate &gt; #{date}",
            "</script>"})
    List<KiaPartsDTO> queryLJDPartsByPrePartsCode(@Param("year") String year, @Param("naif") String naif, @Param("micd") String micd, @Param("ocn") String ocn, @Param("ver") String ver, @Param("date") String date, @Param("partsCode") String partsCodes);

    @Select({"<script>SELECT parts_id,epcRemark,groupName,finalPartName,classify,crnm,bpno,startDate startTime,endDate endTime,finalPartCode finalPartsCode,finalGroupCode groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,count,imgX,imgY",
            " FROM hyundai_parts_LJD_en",
            "WHERE year= #{year}",
            "AND naif = #{naif}",
            "AND micd = #{micd}",
            "AND ocn = #{ocn}",
            "AND ver = #{ver}",
            "AND finalPartCode like '${partsCode}%' ",
            "AND startdate &lt; #{date}",
            "AND enddate &gt; #{date}",
            "</script>"})
    List<KiaPartsDTO> queryLJDPartsByPrePartsCodeEn(@Param("year") String year, @Param("naif") String naif, @Param("micd") String micd, @Param("ocn") String ocn, @Param("ver") String ver, @Param("date") String date, @Param("partsCode") String partsCodes);

    @Select({"<script>SELECT parts_id,groupName,finalPartName,classify,crnm,bpno,startDate startTime,endDate endTime,finalPartCode finalPartsCode,finalGroupCode groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,count,imgX,imgY,epcRemark",
            " FROM hyundai_parts_LJD",
            "WHERE year= #{dto.carTypeYear}",
            "AND naif = #{dto.areaNum}",
            "AND micd = #{dto.micd}",
            "AND ocn = #{dto.ocn}",
            "AND ver = #{dto.ver}",
            "AND parts_id in ",
            "<foreach item ='item' collection = 'mappings' open ='(' separator= ',' close = ')'>",
            "#{item.partsId}",
            "</foreach>",
            "AND startdate &lt; #{dto.makeDate}",
            "AND enddate &gt; #{dto.makeDate}",
            "</script>"})
    List<KiaPartsDTO> queryLJDPartsByMappingV2(@Param("dto") HyundaiKiaVehicleDTO hyundaiKiaVehicleDTO, @Param("mappings") List<HyundaiKiaPartsMappingDTO> l);
}
